/*
 * OpenParts
 * A dynamic-loading components framework for GWT
 * Copyright (C) 2011 Christophe Bouthier  [chris{AT}binary-gastronome{DOT}fr]
 *
 * This work is partially based on work I have done at INRIA (http://www.inria.fr) 
 * in the context of the Qualipso European Project (http://qualipso.org/),
 * The work done at INRIA is Copyright (C) 2006-2011 INRIA
 *
 * This work is distributed under the LGPL version 3
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version 3
 * as published by the Free Software Foundation. See the GNU
 * Lesser General Public License in LGPL.txt for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package fr.openparts.OpenParts.test.gwt.tests;

import com.google.gwt.junit.client.GWTTestCase;

import fr.openparts.OpenParts.client.OPCommandFailureReason;
import fr.openparts.OpenParts.client.OPParams;

/**
 * GWT tests for OPCommandFailureReason.
 * 
 * @author Christophe Bouthier [chris{AT}binary-gastronome{DOT}fr]
 * @creation.date 16 December 2010
 */
public class OPCommandFailureReasonTestGwt extends GWTTestCase {

    private static final String PARAM_NAME = "dummyParamName";
    private static final String PARAM_VALUE = "dummyParamValue";
    private static final String SERVICE = "dummyService";
    private static final String RESOURCE = "dummyResource";
    private static final String ACTION = "dummyAction";
    private static final String PARAM = "dummyParam";
    private static final String SLOTID = "dummySlotId";

    private OPCommandFailureReason commandFailureReason;
    private OPParams params;

    /**
     * Return the name of the tested GWT Module.
     * 
     * @see com.google.gwt.junit.client.GWTTestCase#getModuleName()
     */
    @Override
    public final String getModuleName() {
        return "fr.openparts.OpenParts.test.gwt.TestOpenParts";
    }

    /**
     * Called at the start of each test to set up the action.
     * 
     * @see com.google.gwt.junit.client.GWTTestCase#gwtSetUp()
     */
    @Override
    protected void gwtSetUp() throws Exception {
        super.gwtSetUp();
        params = new OPParams(PARAM_NAME, PARAM_VALUE);
        commandFailureReason = OPCommandFailureReason.commandFailureReasonFactory(OPCommandFailureReason.TYPE_LOAD_TIMEOUT, params);
    }

    /**
     * Called at the end of each test to clean up the mess.
     * 
     * @see com.google.gwt.junit.client.GWTTestCase#gwtTearDown()
     */
    @Override
    protected final void gwtTearDown() throws Exception {
        super.gwtTearDown();
        commandFailureReason = null;
        params = null;
    }

    /**
     * Test creating a command failure reason. Shouldn't get something null.
     */
    public final void testCreatingCommandFailureReason() {
        assertNotNull("command failure reason shouldn't be null", commandFailureReason);
    }

    /**
     * Test trying to create a command failure reason with a null parameter. Should NOT raise an error.
     */
    public final void testCreatingCommandFailureReasonWithNullParameters() {
        try {
            commandFailureReason = OPCommandFailureReason.commandFailureReasonFactory(OPCommandFailureReason.TYPE_LOAD_TIMEOUT, null);
        } catch (Throwable e) {
            fail("OPCommandFailureReason should NOT raise an error when trying to build a command failure reason with null parameters.");
        }
    }

    /**
     * Test command failure reason accessors.
     */
    public final void testCommandFailureReasonAccessors() {
        assertEquals("command failure type should be " + OPCommandFailureReason.TYPE_LOAD_TIMEOUT, OPCommandFailureReason.TYPE_LOAD_TIMEOUT,
                commandFailureReason.getType());
        params = commandFailureReason.getParams();
        assertNotNull("command failure reason params should not be null", params);
        assertEquals("command failure reason params should contains one element", 1, params.size());
        assertEquals("command failure reason params should contains one value", PARAM_VALUE, params.getParamValue(PARAM_NAME));
    }

    /**
     * Test creating a unknown command failure reason.
     */
    public final void testCreatingUnknownCommandFailure() {
        commandFailureReason = OPCommandFailureReason.unknownCommandFailureFactory(-1);
        assertNotNull("unknown command failure shouldn't be null", commandFailureReason);
        assertEquals("command failure reason should be " + OPCommandFailureReason.TYPE_UNKNOW_COMMAND, OPCommandFailureReason.TYPE_UNKNOW_COMMAND,
                commandFailureReason.getType());
        params = commandFailureReason.getParams();
        assertNotNull("command failure reason params should not be null", params);
        assertEquals("command failure reason params should contains one element", 1, params.size());
        assertEquals("command failure reason params should contains " + -1 + " value for command type", "-1",
                params.getParamValue(OPCommandFailureReason.PARAM_COMMAND_TYPE));
    }
    
    /**
     * Test creating a load timeout failure reason.
     */
    public final void testCreatingLoadTimeoutFailure() {
        commandFailureReason = OPCommandFailureReason.loadTimeoutFailureFactory(SERVICE);
        assertNotNull("load timeout failure shouldn't be null", commandFailureReason);
        assertEquals("command failure reason should be " + OPCommandFailureReason.TYPE_LOAD_TIMEOUT, OPCommandFailureReason.TYPE_LOAD_TIMEOUT,
                commandFailureReason.getType());
        params = commandFailureReason.getParams();
        assertNotNull("command failure reason params should not be null", params);
        assertEquals("command failure reason params should contains one element", 1, params.size());
        assertEquals("command failure reason params should contains " + SERVICE + " value for service", SERVICE,
                params.getParamValue(OPCommandFailureReason.PARAM_SERVICE));
    }

    /**
     * Test trying to create a load timeout failure with a null service. Should raise an assertion error.
     */
    public final void testCreatingLoadTimeoutFailureWithNullService() {
        if (assertionsAreEnabled()) {
            try {
                commandFailureReason = OPCommandFailureReason.loadTimeoutFailureFactory(null);
                fail("OPCommandFailureReason should raise an assertion error when trying to build a load timeout failure with a null service.");
            } catch (AssertionError e) {
                assertTrue("Error should be an AssertionError", e instanceof AssertionError);
            }
        }
    }

    /**
     * Test creating a no such view failure reason.
     */
    public final void testCreatingNoSuchViewFailure() {
        commandFailureReason = OPCommandFailureReason.noSuchViewFailureFactory(SERVICE, RESOURCE, ACTION);
        assertNotNull("no such view failure shouldn't be null", commandFailureReason);
        assertEquals("command failure reason should be " + OPCommandFailureReason.TYPE_NO_SUCH_VIEW, OPCommandFailureReason.TYPE_NO_SUCH_VIEW,
                commandFailureReason.getType());
        params = commandFailureReason.getParams();
        assertNotNull("command failure reason params should not be null", params);
        assertEquals("command failure reason params should contains three elements", 3, params.size());
        assertEquals("command failure reason params should contains " + SERVICE + " value for service", SERVICE,
                params.getParamValue(OPCommandFailureReason.PARAM_SERVICE));
        assertEquals("command failure reason params should contains " + RESOURCE + " value for resource", RESOURCE,
                params.getParamValue(OPCommandFailureReason.PARAM_RESOURCE));
        assertEquals("command failure reason params should contains " + ACTION + " value for action", ACTION,
                params.getParamValue(OPCommandFailureReason.PARAM_ACTION));
    }

    /**
     * Test trying to create a no such view failure with a null service. Should raise an assertion error.
     */
    public final void testCreatingNoSuchViewFailureWithNullService() {
        if (assertionsAreEnabled()) {
            try {
                commandFailureReason = OPCommandFailureReason.noSuchViewFailureFactory(null, RESOURCE, ACTION);
                fail("OPCommandFailureReason should raise an assertion error when trying to build a no such view failure with a null service.");
            } catch (AssertionError e) {
                assertTrue("Error should be an AssertionError", e instanceof AssertionError);
            }
        }
    }

    /**
     * Test trying to create a no such view failure with a null resource. Should raise an assertion error.
     */
    public final void testCreatingNoSuchViewFailureWithNullResource() {
        if (assertionsAreEnabled()) {
            try {
                commandFailureReason = OPCommandFailureReason.noSuchViewFailureFactory(SERVICE, null, ACTION);
                fail("OPCommandFailureReason should raise an assertion error when trying to build a no such view failure with a null resource.");
            } catch (AssertionError e) {
                assertTrue("Error should be an AssertionError", e instanceof AssertionError);
            }
        }
    }

    /**
     * Test trying to create a no such view failure with a null action. Should raise an assertion error.
     */
    public final void testCreatingNoSuchViewFailureWithNullAction() {
        if (assertionsAreEnabled()) {
            try {
                commandFailureReason = OPCommandFailureReason.noSuchViewFailureFactory(SERVICE, RESOURCE, null);
                fail("OPCommandFailureReason should raise an assertion error when trying to build a no such view failure with a null action.");
            } catch (AssertionError e) {
                assertTrue("Error should be an AssertionError", e instanceof AssertionError);
            }
        }
    }

    /**
     * Test creating a no such slot failure reason.
     */
    public final void testCreatingNoSuchSlotFailure() {
        commandFailureReason = OPCommandFailureReason.noSuchSlotFailureFactory(SLOTID);
        assertNotNull("no such slot failure shouldn't be null", commandFailureReason);
        assertEquals("command failure reason should be " + OPCommandFailureReason.TYPE_NO_SUCH_SLOT, OPCommandFailureReason.TYPE_NO_SUCH_SLOT,
                commandFailureReason.getType());
        params = commandFailureReason.getParams();
        assertNotNull("command failure reason params should not be null", params);
        assertEquals("command failure reason params should contains one element", 1, params.size());
        assertEquals("command failure reason params should contains " + SLOTID + " value for slot id", SLOTID,
                params.getParamValue(OPCommandFailureReason.PARAM_SLOT_ID));
    }

    /**
     * Test trying to create a no such slot failure with a null slot id. Should raise an assertion error.
     */
    public final void testCreatingNoSuchSlotFailureWithNullSlotId() {
        if (assertionsAreEnabled()) {
            try {
                commandFailureReason = OPCommandFailureReason.noSuchSlotFailureFactory(null);
                fail("OPCommandFailureReason should raise an assertion error when trying to build a no such slot failure with a null slot id.");
            } catch (AssertionError e) {
                assertTrue("Error should be an AssertionError", e instanceof AssertionError);
            }
        }
    }

    /**
     * Test trying to create a no such slot failure with an empty slot id. Should raise an assertion error.
     */
    public final void testCreatingNoSuchSlotFailureWithEmptySlotId() {
        if (assertionsAreEnabled()) {
            try {
                commandFailureReason = OPCommandFailureReason.noSuchSlotFailureFactory("");
                fail("OPCommandFailureReason should raise an assertion error when trying to build a no such slot failure with an empty slot id.");
            } catch (AssertionError e) {
                assertTrue("Error should be an AssertionError", e instanceof AssertionError);
            }
        }
    }

    /**
     * Test creating a missing mandatory param failure reason.
     */
    public final void testCreatingMissingMandatoryParamFailure() {
        commandFailureReason = OPCommandFailureReason.missingMandatoryParamFailureFactory(PARAM);
        assertNotNull("missing mandatory param failure shouldn't be null", commandFailureReason);
        assertEquals("command failure reason should be " + OPCommandFailureReason.TYPE_MISSING_MANDATORY_PARAMS, OPCommandFailureReason.TYPE_MISSING_MANDATORY_PARAMS,
                commandFailureReason.getType());
        params = commandFailureReason.getParams();
        assertNotNull("command failure reason params should not be null", params);
        assertEquals("command failure reason params should contains one element", 1, params.size());
        assertEquals("command failure reason params should contains " + PARAM + " value for missing param", PARAM,
                params.getParamValue(OPCommandFailureReason.PARAM_MISSING_PARAM));
    }

    /**
     * Test trying to create a missing mandatory param failure with a null missing param. Should raise an assertion error.
     */
    public final void testCreatingMissingMandatoryParamFailureWithNullMissingParam() {
        if (assertionsAreEnabled()) {
            try {
                commandFailureReason = OPCommandFailureReason.missingMandatoryParamFailureFactory(null);
                fail("OPCommandFailureReason should raise an assertion error when trying to build a missing mandatory param failure with a null missing param.");
            } catch (AssertionError e) {
                assertTrue("Error should be an AssertionError", e instanceof AssertionError);
            }
        }
    }

    /**
     * Test creating a no such service failure reason.
     */
    public final void testCreatingNoSuchServiceFailure() {
        commandFailureReason = OPCommandFailureReason.noSuchServiceFailureFactory(SERVICE);
        assertNotNull("no such service failure shouldn't be null", commandFailureReason);
        assertEquals("command failure reason should be " + OPCommandFailureReason.TYPE_NO_SUCH_SERVICE, OPCommandFailureReason.TYPE_NO_SUCH_SERVICE,
                commandFailureReason.getType());
        params = commandFailureReason.getParams();
        assertNotNull("command failure reason params should not be null", params);
        assertEquals("command failure reason params should contains one element", 1, params.size());
        assertEquals("command failure reason params should contains " + SERVICE + " value for service", SERVICE,
                params.getParamValue(OPCommandFailureReason.PARAM_SERVICE));
    }

    /**
     * Test trying to create a no such service failure with a null service. Should raise an assertion error.
     */
    public final void testCreatingNoSuchServiceFailureWithNullService() {
        if (assertionsAreEnabled()) {
            try {
                commandFailureReason = OPCommandFailureReason.noSuchServiceFailureFactory(null);
                fail("OPCommandFailureReason should raise an assertion error when trying to build a no such service failure with a null service.");
            } catch (AssertionError e) {
                assertTrue("Error should be an AssertionError", e instanceof AssertionError);
            }
        }
    }

    /**
     * Test creating a pre command failed failure reason.
     */
    public final void testCreatingPreCommandFailedFailure() {
        commandFailureReason = OPCommandFailureReason.preCommandFailedFailureFactory(SERVICE);
        assertNotNull("pre command failed failure shouldn't be null", commandFailureReason);
        assertEquals("command failure reason should be " + OPCommandFailureReason.TYPE_PRE_COMMAND_FAILED, OPCommandFailureReason.TYPE_PRE_COMMAND_FAILED,
                commandFailureReason.getType());
        params = commandFailureReason.getParams();
        assertNotNull("command failure reason params should not be null", params);
        assertEquals("command failure reason params should contains one element", 1, params.size());
        assertEquals("command failure reason params should contains " + SERVICE + " value for service", SERVICE,
                params.getParamValue(OPCommandFailureReason.PARAM_SERVICE));
    }

    /**
     * Test trying to create a pre command failed failure with a null service. Should raise an assertion error.
     */
    public final void testCreatingPreCommandFailedFailureWithNullService() {
        if (assertionsAreEnabled()) {
            try {
                commandFailureReason = OPCommandFailureReason.preCommandFailedFailureFactory(null);
                fail("OPCommandFailureReason should raise an assertion error when trying to build a pre command failed failure with a null service.");
            } catch (AssertionError e) {
                assertTrue("Error should be an AssertionError", e instanceof AssertionError);
            }
        }
    }

    /**
     * Test creating a no such id in the page failure reason.
     */
    public final void testCreatingNoSuchIdInThePageFailure() {
        commandFailureReason = OPCommandFailureReason.noSuchIdOnThePageFailureFactory(SLOTID);
        assertNotNull("no such id in the page failure shouldn't be null", commandFailureReason);
        assertEquals("command failure reason should be " + OPCommandFailureReason.TYPE_NO_SUCH_ID_IN_THE_PAGE, OPCommandFailureReason.TYPE_NO_SUCH_ID_IN_THE_PAGE,
                commandFailureReason.getType());
        params = commandFailureReason.getParams();
        assertNotNull("command failure reason params should not be null", params);
        assertEquals("command failure reason params should contains one element", 1, params.size());
        assertEquals("command failure reason params should contains " + SLOTID + " value for slot id", SLOTID,
                params.getParamValue(OPCommandFailureReason.PARAM_SLOT_ID));
    }

    /**
     * Test trying to create a no such id in the page failure with a null slot id. Should raise an assertion error.
     */
    public final void testCreatingNoSuchIdInThePageFailureWithNullSlotId() {
        if (assertionsAreEnabled()) {
            try {
                commandFailureReason = OPCommandFailureReason.noSuchIdOnThePageFailureFactory(null);
                fail("OPCommandFailureReason should raise an assertion error when trying to build a no such id in the page failure with a null slot id.");
            } catch (AssertionError e) {
                assertTrue("Error should be an AssertionError", e instanceof AssertionError);
            }
        }
    }

    /**
     * Test trying to create a no such id in the page failure with an empty slot id. Should raise an assertion error.
     */
    public final void testCreatingNoSuchIdInThePageFailureWithEmptySlotId() {
        if (assertionsAreEnabled()) {
            try {
                commandFailureReason = OPCommandFailureReason.noSuchIdOnThePageFailureFactory("");
                fail("OPCommandFailureReason should raise an assertion error when trying to build a no such id in the page failure with an empty slot id.");
            } catch (AssertionError e) {
                assertTrue("Error should be an AssertionError", e instanceof AssertionError);
            }
        }
    }

    /**
     * Test creating a given id is not a slot failure reason.
     */
    public final void testCreatingGivenIdIsNotASlotFailure() {
        commandFailureReason = OPCommandFailureReason.givenIdIsNotASlotFailureFactory(SLOTID);
        assertNotNull("given id is not a slot failure shouldn't be null", commandFailureReason);
        assertEquals("command failure reason should be " + OPCommandFailureReason.TYPE_GIVEN_ID_IS_NOT_A_SLOT, OPCommandFailureReason.TYPE_GIVEN_ID_IS_NOT_A_SLOT,
                commandFailureReason.getType());
        params = commandFailureReason.getParams();
        assertNotNull("command failure reason params should not be null", params);
        assertEquals("command failure reason params should contains one element", 1, params.size());
        assertEquals("command failure reason params should contains " + SLOTID + " value for slot id", SLOTID,
                params.getParamValue(OPCommandFailureReason.PARAM_SLOT_ID));
    }

    /**
     * Test trying to create a given id is not a slot failure with a null slot id. Should raise an assertion error.
     */
    public final void testCreatingGivenIdIsNotASlotFailureWithNullSlotId() {
        if (assertionsAreEnabled()) {
            try {
                commandFailureReason = OPCommandFailureReason.givenIdIsNotASlotFailureFactory(null);
                fail("OPCommandFailureReason should raise an assertion error when trying to build a given id is not a slot failure with a null slot id.");
            } catch (AssertionError e) {
                assertTrue("Error should be an AssertionError", e instanceof AssertionError);
            }
        }
    }

    /**
     * Test trying to create a given id is not a slot failure with an empty slot id. Should raise an assertion error.
     */
    public final void testCreatingGivenIdIsNotASlotFailureWithEmptySlotId() {
        if (assertionsAreEnabled()) {
            try {
                commandFailureReason = OPCommandFailureReason.givenIdIsNotASlotFailureFactory("");
                fail("OPCommandFailureReason should raise an assertion error when trying to build a given id is not a slot failure with an empty slot id.");
            } catch (AssertionError e) {
                assertTrue("Error should be an AssertionError", e instanceof AssertionError);
            }
        }
    }

    /**
     * Test creating a no view attached to proxy failure reason.
     */
    public final void testCreatingNoViewAttachedToProxyFailure() {
        commandFailureReason = OPCommandFailureReason.noViewAttachedToProxyFailureFactory();
        assertNotNull("no view attached to proxy failure shouldn't be null", commandFailureReason);
        assertEquals("command failure reason should be " + OPCommandFailureReason.TYPE_NO_VIEW_ATTACHED_TO_PROXY, OPCommandFailureReason.TYPE_NO_VIEW_ATTACHED_TO_PROXY,
                commandFailureReason.getType());
        assertNull("command failure reason params should be null", commandFailureReason.getParams());
    }

    /**
     * Test creating a no slot attached to proxy failure reason.
     */
    public final void testCreatingNoSlotAttachedToProxyFailure() {
        commandFailureReason = OPCommandFailureReason.noSlotAttachedToProxyFailureFactory();
        assertNotNull("no slot attached to proxy failure shouldn't be null", commandFailureReason);
        assertEquals("command failure reason should be " + OPCommandFailureReason.TYPE_NO_SLOT_ATTACHED_TO_PROXY, OPCommandFailureReason.TYPE_NO_SLOT_ATTACHED_TO_PROXY,
                commandFailureReason.getType());
        assertNull("command failure reason params should be null", commandFailureReason.getParams());
    }
    
    /**
     * Test the description of an unknown command failure type.
     */
    public final void testDescriptionForUnknownCommandFailureType() {
        commandFailureReason = OPCommandFailureReason.unknownCommandFailureFactory(-1);
        final String typeDescription = commandFailureReason.getTypeDescription();
        assertNotNull("type description for unknown command failure shouldn't be null", typeDescription);
        assertEquals("type description for unknown command failure should be: Unknown command", "Unknown command", typeDescription);
    }
    
    /**
     * Test the description of a load timeout failure type.
     */
    public final void testDescriptionForLoadTimeoutFailureType() {
        commandFailureReason = OPCommandFailureReason.loadTimeoutFailureFactory(SERVICE);
        final String typeDescription = commandFailureReason.getTypeDescription();
        assertNotNull("type description for load timeout failure shouldn't be null", typeDescription);
        assertEquals("type description for load timeout failure should be: Load timeout", "Load timeout", typeDescription);
    }
    
    /**
     * Test the description of a no such view failure type.
     */
    public final void testDescriptionForNoSuchViewFailureType() {
        commandFailureReason = OPCommandFailureReason.noSuchViewFailureFactory(SERVICE, RESOURCE, ACTION);
        final String typeDescription = commandFailureReason.getTypeDescription();
        assertNotNull("type description for no such view failure shouldn't be null", typeDescription);
        assertEquals("type description for no such view failure should be: No such view", "No such view", typeDescription);
    }
    
    /**
     * Test the description of a no such slot failure type.
     */
    public final void testDescriptionForNoSuchSlotFailureType() {
        commandFailureReason = OPCommandFailureReason.noSuchSlotFailureFactory(SLOTID);
        final String typeDescription = commandFailureReason.getTypeDescription();
        assertNotNull("type description for no such slot failure shouldn't be null", typeDescription);
        assertEquals("type description for no such slot failure should be: No such slot", "No such slot", typeDescription);
    }
    
    /**
     * Test the description of a missing mandatory param failure type.
     */
    public final void testDescriptionForMissingMandatoryParamFailureType() {
        commandFailureReason = OPCommandFailureReason.missingMandatoryParamFailureFactory(PARAM);
        final String typeDescription = commandFailureReason.getTypeDescription();
        assertNotNull("type description for missing mandatory param failure shouldn't be null", typeDescription);
        assertEquals("type description for missing mandatory param failure should be: Missing mandatory param", "Missing mandatory param", typeDescription);
    }
    
    /**
     * Test the description of a no such service failure type.
     */
    public final void testDescriptionForNoSuchServiceFailureType() {
        commandFailureReason = OPCommandFailureReason.noSuchServiceFailureFactory(SERVICE);
        final String typeDescription = commandFailureReason.getTypeDescription();
        assertNotNull("type description for no such service failure shouldn't be null", typeDescription);
        assertEquals("type description for no such service failure should be: No such service", "No such service", typeDescription);
    }
    
    /**
     * Test the description of a pre command failed failure type.
     */
    public final void testDescriptionForPreCommandFailedFailureType() {
        commandFailureReason = OPCommandFailureReason.preCommandFailedFailureFactory(SERVICE);
        final String typeDescription = commandFailureReason.getTypeDescription();
        assertNotNull("type description for pre command failed failure shouldn't be null", typeDescription);
        assertEquals("type description for pre command failed failure should be: Pre-command failed", "Pre-command failed", typeDescription);
    }
    
    /**
     * Test the description of a no such id on the page failure type.
     */
    public final void testDescriptionForNoSuchIdInThePageFailureType() {
        commandFailureReason = OPCommandFailureReason.noSuchIdOnThePageFailureFactory(SLOTID);
        final String typeDescription = commandFailureReason.getTypeDescription();
        assertNotNull("type description for no such id in the page failure shouldn't be null", typeDescription);
        assertEquals("type description for no such id in the page failure should be: No such id in the page", "No such id in the page", typeDescription);
    }
    
    /**
     * Test the description of a given id is not a slot failure type.
     */
    public final void testDescriptionForGivenIdIsNotASlotFailureType() {
        commandFailureReason = OPCommandFailureReason.givenIdIsNotASlotFailureFactory(SLOTID);
        final String typeDescription = commandFailureReason.getTypeDescription();
        assertNotNull("type description for given id is not a slot failure shouldn't be null", typeDescription);
        assertEquals("type description for given id is not a slot failure should be: Given id is not a slot", "Given id is not a slot", typeDescription);
    }
    
    /**
     * Test the description of a no view attached to proxy failure type.
     */
    public final void testDescriptionForNoViewAttachedToProxyFailureType() {
        commandFailureReason = OPCommandFailureReason.noViewAttachedToProxyFailureFactory();
        final String typeDescription = commandFailureReason.getTypeDescription();
        assertNotNull("type description for no view attached to proxy failure shouldn't be null", typeDescription);
        assertEquals("type description for no view attached to proxy failure should be: No view attached to proxy", "No view attached to proxy", typeDescription);
    }
    
    /**
     * Test the description of a no slot attached to proxy failure type.
     */
    public final void testDescriptionForNoSlotAttachedToProxyFailureType() {
        commandFailureReason = OPCommandFailureReason.noSlotAttachedToProxyFailureFactory();
        final String typeDescription = commandFailureReason.getTypeDescription();
        assertNotNull("type description for no slot attached to proxy failure shouldn't be null", typeDescription);
        assertEquals("type description for no slot attached to proxy failure should be: No slot attached to proxy", "No slot attached to proxy", typeDescription);
    }
    
    /**
     * Test the description of an unknown failure reason type.
     */
    public final void testDescriptionForUnknownFailureReasonType() {
        commandFailureReason = OPCommandFailureReason.commandFailureReasonFactory(-1, null);
        final String typeDescription = commandFailureReason.getTypeDescription();
        assertNotNull("type description for unknown failure type shouldn't be null", typeDescription);
        assertEquals("type description for unknown failure type should be: Unknown failure reason type", "Unknown failure reason type", typeDescription);
    }

    /**
     * Test the description of an unknown command failure.
     */
    public final void testDescriptionForUnknownCommandFailure() {
        commandFailureReason = OPCommandFailureReason.unknownCommandFailureFactory(-1);
        final String description = commandFailureReason.getDescription();
        assertNotNull("description for unknown command failure shouldn't be null", description);
        assertEquals("description for unknown command failure is not as planned", "Unknown command: Command type -1 is unknown.", description);
    }
    
    /**
     * Test the description of a load timeout failure.
     */
    public final void testDescriptionForLoadTimeoutFailure() {
        commandFailureReason = OPCommandFailureReason.loadTimeoutFailureFactory(SERVICE);
        final String description = commandFailureReason.getDescription();
        assertNotNull("description for load timeout failure shouldn't be null", description);
        assertEquals("description for load timeout failure is not as planned", "Load timeout: Loading service dummyService failed (timed out).", description);
    }
    
    /**
     * Test the description of a no such view failure.
     */
    public final void testDescriptionForNoSuchViewFailure() {
        commandFailureReason = OPCommandFailureReason.noSuchViewFailureFactory(SERVICE, RESOURCE, ACTION);
        final String description = commandFailureReason.getDescription();
        assertNotNull("description for no such view failure shouldn't be null", description);
        assertEquals("description for no such view failure is not as planned", "No such view: Cannot find a view binded for service dummyService, resource dummyResource and action dummyAction.", description);
    }
    
    /**
     * Test the description of a no such slot failure.
     */
    public final void testDescriptionForNoSuchSlotFailure() {
        commandFailureReason = OPCommandFailureReason.noSuchSlotFailureFactory(SLOTID);
        final String description = commandFailureReason.getDescription();
        assertNotNull("description for no such slot failure shouldn't be null", description);
        assertEquals("description for no such slot failure is not as planned", "No such slot: Cannot find a slot with the id dummySlotId in the page.", description);
    }
    
    /**
     * Test the description of a missing mandatory param failure.
     */
    public final void testDescriptionForMissingMandatoryParamFailure() {
        commandFailureReason = OPCommandFailureReason.missingMandatoryParamFailureFactory(PARAM);
        final String description = commandFailureReason.getDescription();
        assertNotNull("description for missing mandatory param failure shouldn't be null", description);
        assertEquals("description for missing mandatory param failure is not as planned", "Missing mandatory param: Calling view display failed because the mandatory param dummyParam was missing.", description);
    }
    
    /**
     * Test the description of a no such service failure.
     */
    public final void testDescriptionForNoSuchServiceFailure() {
        commandFailureReason = OPCommandFailureReason.noSuchServiceFailureFactory(SERVICE);
        final String description = commandFailureReason.getDescription();
        assertNotNull("description for no such service failure shouldn't be null", description);
        assertEquals("description for no such service failure is not as planned", "No such service: Cannot find a binded service named dummyService.", description);
    }
    
    /**
     * Test the description of a pre command failed failure.
     */
    public final void testDescriptionForPreCommandFailedFailure() {
        commandFailureReason = OPCommandFailureReason.preCommandFailedFailureFactory(SERVICE);
        final String description = commandFailureReason.getDescription();
        assertNotNull("description for pre command failed failure shouldn't be null", description);
        assertEquals("description for pre command failed failure is not as planned", "Pre-command failed: The service dummyService, necessary for the command, wasn't loaded. Trying to load it, before executing the command, failed (timeout).", description);
    }
    
    /**
     * Test the description of a no such id on the page failure.
     */
    public final void testDescriptionForNoSuchIdInThePageFailure() {
        commandFailureReason = OPCommandFailureReason.noSuchIdOnThePageFailureFactory(SLOTID);
        final String description = commandFailureReason.getDescription();
        assertNotNull("description for no such id in the page failure shouldn't be null", description);
        assertEquals("description for no such id in the page failure is not as planned", "No such id in the page: Cannot find an element with the id dummySlotId in the page.", description);
    }
    
    /**
     * Test the description of a given id is not a slot failure.
     */
    public final void testDescriptionForGivenIdIsNotASlotFailure() {
        commandFailureReason = OPCommandFailureReason.givenIdIsNotASlotFailureFactory(SLOTID);
        final String description = commandFailureReason.getDescription();
        assertNotNull("description for given id is not a slot failure shouldn't be null", description);
        assertEquals("description for given id is not a slot failure is not as planned", "Given id is not a slot: The element with the id dummySlotId found in the page is not a slot.", description);
    }
    
    /**
     * Test the description of a no view attached to proxy failure.
     */
    public final void testDescriptionForNoViewAttachedToProxyFailure() {
        commandFailureReason = OPCommandFailureReason.noViewAttachedToProxyFailureFactory();
        final String description = commandFailureReason.getDescription();
        assertNotNull("description for no view attached to proxy failure shouldn't be null", description);
        assertEquals("description for no view attached to proxy failure is not as planned", "No view attached to proxy: There is no view attached to this proxy.", description);
    }
    
    /**
     * Test the description of a no slot attached to proxy failure.
     */
    public final void testDescriptionForNoSlotAttachedToProxyFailure() {
        commandFailureReason = OPCommandFailureReason.noSlotAttachedToProxyFailureFactory();
        final String description = commandFailureReason.getDescription();
        assertNotNull("description for no slot attached to proxy failure shouldn't be null", description);
        assertEquals("description for no slot attached to proxy failure is not as planned", "No slot attached to proxy: There is no slot attached to this proxy.", description);
    }
    
    /**
     * Test the description of an unknown failure reason.
     */
    public final void testDescriptionForUnknownFailureReason() {
        commandFailureReason = OPCommandFailureReason.commandFailureReasonFactory(-1, null);
        final String description = commandFailureReason.getDescription();
        assertNotNull("description for unknown failure shouldn't be null", description);
        assertEquals("description for unknown failure is not as planned", "Unknown failure reason type: Executing the command failed for an unknown reason.", description);
    }
    
    /**
     * Check if assertions are enabled.
     * 
     * @return true if assertions are enabled, false otherwise
     */
    private final boolean assertionsAreEnabled() {
        try {
            assert false;
            return false;
        } catch (AssertionError e) {
            return true;
        }
    }
}
